﻿/*
	Date:			05/19/2012
	Author:         Fabien Olousouzian
	License:      	Microsoft Public License (Ms-PL)
	Product:        XNA Shader Composer - Project
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace Shader_Composer.Primitive
{
    /// <summary>
    /// Draw an axis in position 0,0,0
    /// </summary>
    class Axis
    {
        #region Attributes

        private Line _x;
        private Line _y;
        private Line _z;
        private SpriteFont _font;
        private bool _active;

        #endregion

        #region Methods

        /// <summary>
        /// Ctor
        /// </summary>
        public Axis()
        {
            _x = new Line();
            _y = new Line();
            _z = new Line();
            _active = true;
            InitLines(1000);
        }

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="length"></param>
        public Axis(uint length)
        {
            _x = new Line();
            _y = new Line();
            _z = new Line();
            _active = true;
            InitLines(length);
        }

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="length"></param>
        private void InitLines(uint length)
        {
            _x.FirstPosition = new VertexPositionColor(new Vector3(0, 0, 0), Color.Blue);
            _x.SecondPosition = new VertexPositionColor(new Vector3(length, 0, 0), Color.Blue);

            _y.FirstPosition = new VertexPositionColor(new Vector3(0, 0, 0), Color.Red);
            _y.SecondPosition = new VertexPositionColor(new Vector3(0, length, 0), Color.Red);

            _z.FirstPosition = new VertexPositionColor(new Vector3(0, 0, 0), Color.Green);
            _z.SecondPosition = new VertexPositionColor(new Vector3(0, 0, length), Color.Green);
        }

        /// <summary>
        /// Load the font
        /// </summary>
        /// <param name="content"></param>
        public void Load(ContentManager content)
        {
            _font = content.Load<SpriteFont>(@"Font\AxisFont");
        }

        /// <summary>
        /// Load the font
        /// </summary>
        /// <param name="content"></param>
        /// <param name="fontName"></param>
        public void Load(ContentManager content, string fontName)
        {
            _font = content.Load<SpriteFont>(fontName);
        }


        /// <summary>
        /// Update
        /// </summary>
        /// <param name="device"></param>
        public void Update(ref Device device)
        {
            if (device.keyJustPressed(Keys.H) || device.buttonJustPressed(Buttons.DPadUp))
                _active = !_active;
        }

        /// <summary>
        /// Draw the Axis
        /// </summary>
        /// <param name="effect"></param>
        /// <param name="graphics"></param>
        public void Draw(ref BasicEffect effect, GraphicsDevice graphics)
        {
            if (_active)
            {
                _x.Draw(effect, graphics);
                _y.Draw(effect, graphics);
                _z.Draw(effect, graphics);
            }
        }

        /// <summary>
        /// Add info for debugging
        /// </summary>
        public void AddInfoDebug()
        {
            DisplayInfoDebug.Instance.Buffer += "Axis - x y z\n";
        }

        #endregion

        #region Getter & Setter


        /// <summary>
        /// Get & set the X line
        /// </summary>
        public Line X
        {
            get { return _x; }
            set { _x = value; }
        }

        /// <summary>
        /// Get & set the Y line
        /// </summary>
        public Line Y
        {
            get { return _y; }
            set { _y = value; }
        }

        /// <summary>
        /// Get & set the Z line
        /// </summary>
        public Line Z
        {
            get { return _z; }
            set { _z = value; }
        }

        #endregion

    }
}
